# encoding    : utf-8
# author      : 伦裕如
# project     : hrjt_-py1
# file        : exception1
# time        : 2024-06-19 上午10:54 

import pymysql

# 创建数据库连接
try:
    db = pymysql.connect(
        host = 'localhost',
        port = 3306,
        database = 'jiangsu',
        user = 'root',
        password = 'root',
        charset = 'utf8'
    )
except Exception as e:
    raise '数据库连接异常，检查配置信息是否正确'

# 创建游标
try:
    with db.cursor() as cursor:
        sql = 'select * from student'
        cursor.execute(sql)
        data = cursor.fetchone()
        print(data)
except Exception as e:
    print(f'数据库操作异常，检查SQL语句是否正确： {sql}')
    raise e
finally:
    db.close()

print('sadf')



 